# Written by koya
# -*- coding: utf8 -*-

import pygame
from pygame.locals import *

import font


#该类实现信息显示在屏幕上,这里把其作为一个游戏对象
#信息的构造函数里面有信息内容,显示信息的位置以及信息的大小
#该类还实现信息的渐渐消失
#self.fadespeed为消失的速度
#self.trans 为信息的透明度

class Message( pygame.sprite.Sprite ):
    
      def __init__( self, msg, pos, size = 12 ):
          
            super( Message, self ).__init__( self.containers )
            
            self.msg = msg
            self.pos = pos
            self.font = font.load_font( "Hemi Head 426.TTF", size )
            self.image = self.font.render( self.msg, 0, ( 255, 255, 255 ) ).convert()
            self.rect = self.image.get_rect( center = pos )
            self.life = 255
            self.fadespeed = 8
            if size == 12:
                  self.fadespeed = 8
            if size >= 20:
                  self.fadespeed = 4

      def update( self ):
          
            self.life -= self.fadespeed
            if self.life <= 0:
                  self.kill()
            self.image.set_alpha( self.life, RLEACCEL )

      def draw( self, screen ):

            screen.blit( self.image, self.rect )
